import { Component, OnInit } from '@angular/core';
import { HttpService } from '../../service/http.service';
import { HttpRouterService } from '../../service/http-router.service';
import { StorageService } from '../../service/storage.service';
import { Router, ActivatedRoute } from '@angular/router';
import { CityData } from './city.data';
import _ from 'underscore';

@Component({
  selector: 'app-fossick',
  templateUrl: './fossick.component.html',
  styleUrls: ['./fossick.component.less']
})
export class FossickComponent implements OnInit {

  public step = '';

  public _cityList = [];
  public province = '';
  public isShow = false;
  public showProvince = '全国';

  public danList = [];
  public danProvince = '';
  public param = '';



  constructor(
    private _http: HttpService,
    private _router: Router,
    private _activatedRoute: ActivatedRoute,
    private _storage: StorageService,
    private _httpRouter: HttpRouterService
  ) { }

  ngOnInit() {
    this._activatedRoute.queryParams.subscribe(params => {
      this.param = params.param;
    });
    this._cityList = CityData;
    this.getDanList();
  }

  // 城市选择框
  showChoose() {
    this.isShow = true;
  }

  // 选择城市
  checkProvince(id= '', name= '全国') {
    this.province = id;
    this.showProvince = name;
    this.isShow = false;
    this.param = 'province=' + this.province;
    this.getDanList();
  }

  // 展示订单
  getDanList() {
    this._http.post(this._httpRouter.danList, this.param).then(res => {
      if (res.code === 1) {
        this.danList = res.data;
      }
    });
  }

}
